package com.transaction.demo.order.controller;

import com.transaction.demo.order.vo.PayReqVo;
import com.transaction.demo.trade.vo.req.InitPaymentOrderReqVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import lombok.extern.slf4j.Slf4j;

import com.transaction.demo.common.util.JsonUtils;
import com.transaction.demo.common.util.Result;
import com.transaction.demo.message.TradePaymentManagerService;
import com.transaction.demo.message.TradePaymentQueryService;

import javax.validation.Valid;

/**
 * 描述：支付下单
 * 作者：马庆智
 * 日期：2023/5/5 13:47
 */
@Api(tags = "支付下单")
@RestController
@RequestMapping("/v1")
@Slf4j
public class OrderController {

    @Autowired
    private TradePaymentManagerService managerService;


    /**
     * 支付下单
     *
     * @return String
     * @author 马庆智
     * @date: 2023/5/5 13:49
     */
    @ApiOperation("支付下单")
    @PostMapping("/testPay")
    public Result<String> testPay(@RequestBody @Valid PayReqVo vo) {
        log.info("接收到第三方订单参数：{}", JsonUtils.toJson(vo));

        InitPaymentOrderReqVo reqVo = InitPaymentOrderReqVo.builder().businessId(vo.getBusinessId()).price(vo.getPrice())
                .productName(vo.getProductName()).remark(vo.getRemark()).build();
        managerService.initPaymentOrder(reqVo);

        return Result.success("success");
    }

    @Transactional
    public void querySql(){

    }

    @PostMapping("testQuery")
    public  Result<String> testQuery(){
          return Result.success("testQuery");
    }

}
